package com.algorithm.cjm.jiaocai.ch4;

/**
 * Created by jieming.chen on 2020/1/30
 */
public class Example13 {
    float[] a = new float[]{1.0f, 2.0f, 3.0f};

    void maxmin(int i, int j, float fmax, float fmin) {
        int mid;
        Float lmax = 0.0f, lmin = 0.0f, rmax = 0.0f, rmin = 0.0f;
        if (i == j) {
            fmax = a[i];
            fmin = a[i];
        } else if (i == j - 1) {
            if (a[i] < a[j]) {
                fmax = a[j];
                fmin = a[i];
            } else {
                fmax = a[i];
                fmin = a[j];
            }
        } else {
            mid = (i + j)/2;
            maxmin(i, mid, lmax, lmin);
            maxmin(mid + 1, j, rmax, rmin);
            if (lmax > rmax) {
                fmax = lmax;
            } else {
                fmax = rmax;
            }
            if (lmin > rmin) {
                fmin = rmin;
            } else {
                fmin = lmin;
            }
        }
    }

    public static void main(String[] args) {
        Float a = 0.0f;
        Float b = 0.0f;

        Example13 example13 = new Example13();
        example13.maxmin(0, 2, a, b);
    }
}
